'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	const currentDate = new Date()
	const year = currentDate.getFullYear()
	const month = currentDate.getMonth()
	const day = currentDate.getDate()
	const firstDay = new Date(year, month, day) 
	const lastDay = new Date(year, month, day+1) 

	const $ = db.command.aggregate
	let res = await db
		.collection('order')
		.aggregate()
		.match({
			store_id: event.store_id,
			buy_time: db.command.gte(firstDay.getTime()).and(db.command.lte(lastDay.getTime()))
		})
		.group({
			_id: null,
			sumPrice: $.sum('$sum_price')
		})
		.end()
	return res;
};